package com.antipov.odp.rmi.client;

import com.antipov.odp.rmi.intf.PointService;
import com.antipov.odp.rmi.valueobjects.Point;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Locale;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Andrew Antipov
 * Date: 19.02.14
 * Time: 1:26
 */
public class RMIClient {

	public static void main(String[] args) {
		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new SecurityManager());
		}

		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();

		Point first = new Point(x1, y1);
		Point second = new Point(x2, y2);
		try {
			Registry registry = LocateRegistry.getRegistry(null);
			PointService pointService = (PointService)registry.lookup("PointService");
			double d = pointService.distance(first, second);
			double lr = pointService.lengthRadius(first, second);
			double ld = pointService.lengthDiameter(first, second);
			double sr = pointService.squareRadius(first, second);
			double sd = pointService.squareDiameter(first, second);
			System.out.printf(Locale.US, "Distance: %.3f\n", d);
			System.out.printf(Locale.US, "Length radius: %.3f\n", lr);
			System.out.printf(Locale.US, "Length diameter: %.3f\n", ld);
			System.out.printf(Locale.US, "Square radius: %.3f\n", sr);
			System.out.printf(Locale.US, "Square diameter: %.3f\n", sd);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
